#!/bin/bash
# a tiny script to test webcams using mplayer
# options are self explanatory :)

DEVICE="video0"
AUDIO=":noaudio"
FILTER="-vf-add pp=hb:a/vb:a,hqdn3d,mirror"
V4L=""
EXTRA=""
WIDTH="640"
HEIGHT="480"
RESOLUTION="-x 800 -y 600"
FPS=""

for x in $*; do
    case "${x}" in
        video[0-9]*)
            DEVICE="${x}"
        ;;
        -v4l2)
            V4L=":driver=v4l2"
            FPS="-fps 60"
        ;;
        -v4l)
            V4L=":driver=v4l"
            FPS="-fps 60"
        ;;
        -audio)
            AUDIO=""
        ;;
        -w[0-9]*)
            WIDTH=`echo "${x}"|cut -c 4-`
        ;;
        -h[0-9]*)
            HEIGHT=`echo "${x}"|cut -c 4-`
        ;;
        -forcefps)
            FPS="-fps 30"
        ;;
        -nores)
            RESOLUTION=""
        ;;
        -nofilter)
            FILTER=""
        ;;
        *)
            EXTRA="$EXTRA ${x}"
        ;;
    esac
done

# main
mplayer tv:// -tv device=/dev/$DEVICE:width=$WIDTH:height=$HEIGHT$V4L$AUDIO $RESOLUTION $FILTER $FPS $EXTRA

